using System.Collections.Generic;
using System.Linq;
using Godot;

namespace Arcane.Source.Data
{
    public class TextureDB
    {
        private readonly Dictionary<StringName, Texture2D> _textures = [];

        public Texture2D Default => _textures[StringNames.DEFAULT];

        // Load textures from root dir recursively.
        public void Load(string loadDir)
        {
            LoadUtil.LoadRecursive<Texture2D>(
                loadDir,
                (name, texture) => _textures.Add(name, texture),
                file => !file.EndsWith("import")
            );
        }

        public Texture2D Get(StringName name) => _textures.TryGetValue(name, out var tex) ? tex : Default;
    }
}